def get_headers(h_str):

    # 将字符串按行切割
    li = [header.strip() for header in h_str.splitlines() if header.strip()]
    # 将字符串按行分隔，并去掉将":"开头的字符的":"
    s_li = [i[1:] if i.startswith(':') else i for i in li]
    headers = {}
    # 将列表转换成headers格式
    for i in s_li:
        key, value = i.split(':', 1)
        # 去除复制过来request headers中的空格
        headers[key.strip()] = value.strip()

    return headers


header = '''
    :authority: www.mca.gov.in
    :method: GET
    :path: /content/mca/global/en/data-and-reports/company-statistics/indian-foreign-companies-llps/total-companies-registered.html
    :scheme: https
    pragma: no-cache
    referer: https://www.mca.gov.in/content/mca/global/en/data-and-reports/company-statistics/indian-foreign-companies-llps/total-companies-registered.html
    sec-ch-ua: " Not;A Brand";v="99", "Google Chrome";v="97", "Chromium";v="97"
    sec-ch-ua-mobile: ?0
    sec-ch-ua-platform: "Windows"
    sec-fetch-dest: document
    sec-fetch-mode: navigate
    sec-fetch-site: same-origin
    sec-fetch-user: ?1
    upgrade-insecure-requests: 1
    user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36
    '''

# print(get_headers(header))